import type { CodeType, PatientType, User, UserType } from '@/types/user'
import { request } from '@/utils/request'

/**
 * 密码登录
 */
export const login = (mobile: string, password: string) => {
  return request<User>('login/password', 'post', {
    mobile,
    password
  })
}

/**
 *  验证码
 */
export const sendMobileCode = (mobile: string, type: CodeType) => {
  return request<{ code: string }>('code', 'get', {
    mobile,
    type
  })
}

/**
 * 短信登录
 */
export const loginByMobile = (mobile: string, code: string) => {
  return request<User>('login', 'POST', {
    mobile,
    code
  })
}

/**
 * 获取个人用户信息
 */
export const getPersonInfo = () => {
  return request<UserType>('patient/myUser', 'GET')
}

/**
 *  患者列表
 */
export const patientList = () => {
  return request<PatientType[]>('patient/mylist', 'get')
}

/**
 *  添加患者, 添加患者我们不需要他的返回值, 那么就不需要进行定义了
 *  patient => 他是一个对象
 */

export const addPatient = (patient: PatientType) => {
  return request('patient/add', 'POST', patient)
}

/**
 * 患者详情
 */

export const patientDetail = (id: string) => {
  return request<PatientType>(`/patient/info/${id}`, 'GET')
}

/**
 * 编辑患者
 */

export const editPatient = (patient: PatientType) => {
  return request<PatientType>('patient/update', 'PUT', patient)
}

/**
 * 删除用户
 */

export const delPatient = (id: string) => {
  return request(`patient/del/${id}`, 'delete')
}

/**
 * 患者详情
 */

export const getPatientDetail = (id: string) => {
  return request<PatientType>(`/patient/info/${id}`, 'GET')
}

// qq登录
export const loginByQQ = (openId: string) =>
  request<User>('/login/thirdparty', 'POST', { openId, source: 'qq' })

// 绑定手机号
export const bindMobile = (data: { mobile: string; code: string; openId: string }) =>
  request<User>('/login/binding', 'POST', data)
